<template>
	<view class="gl-container">
		<swiper class="gl-page-swiper" :current="currentIndex" :disable-touch="true" @change="pageChange"
			:style="{height:swiperH+'px'}">
			<swiper-item>
				<placeList ref="subPlaceList" @showInfo="navPlaceInfo"></placeList>
			</swiper-item>
			<swiper-item>
				<placeInfo ref="subPlaceInfo" @navBack="navPlaceList"></placeInfo>
			</swiper-item>
		</swiper>
	</view>

</template>

<script>
	import utils from '@/common/utils.js'
	import placeList from '@/pages/place/swiper-list.vue'
	import placeInfo from '@/pages/place/swiper-info.vue'
	export default {
		data() {
			return {
				swiperH: 0, // swiper高度
				name: 'subPlaceList',
				sConf: getApp().globalData,
				currentIndex: 0,
			}
		},
		mounted() {
			console.log('页面挂载', '商户列表');
			let window = uni.getWindowInfo();
			this.designLayout(window.windowHeight);
			// this.refresh();
			// let subnav = uni.getStorageSync('subnav');
			// let curTab = subnav.find(item => item.component === this.name).subTab || 0
			// this.currentIndex = curTab
		},
		components: {
			placeList,
			placeInfo
		},
		inject: ['localPages'],
		methods: {
			curTabChange() {
				console.log('curTabChange', this.localPages);
				return this.localPages
			},
			/**
			 * 滑动换页回调
			 */
			pageChange(e) {
				console.log('pageChange', this.localPages);
				// uni.setStorageSync('curSubTab', e.detail.current);
				this.$emit('subTabChange', e.detail.current)
			},
			designLayout(wh) {
				console.log('计算窗口布局');
				// 计算窗口高度
				this.$nextTick(() => {
					const query = uni.createSelectorQuery().in(this);
					query.select('.gl-page-swiper').boundingClientRect();
					query.exec((res) => {
						console.log('swiper窗口', Math.ceil(res[0].top));
						this.swiperH = wh - Math.ceil(res[0].top) - 10 - 10;
					});
				})
			},
			/**
			 * 导航商户列表
			 */
			navPlaceList() {
				this.$refs.subPlaceList.loadDefData()
				this.currentIndex = 0;
			},
			/**
			 * 导航商户详情
			 */
			navPlaceInfo(e) {
				console.log('navPlaceInfo');
				this.$refs.subPlaceInfo.loadDefData(e);
				this.currentIndex = 1;
			}

		}
	}
</script>

<style lang="scss" scoped>

</style>